﻿using System.Web.Http;
using DTCash.Logger;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using DTCash.Redis;
using Uranus.Common;
using Uranus.Service;
using Uranus.Service.CompanyService;
using Uranus.Service.ForwardProductService;
using Uranus.Service.OrderService;
using Uranus.Service.OtherService;
using Uranus.Service.ProductService;
using Uranus.Service.RepaymentService;
using Uranus.Service.UserService;
using Uranus.WeiStationAPI.App_Start;
using Uranus.WeiStationAPI.Common;
using Uranus.WeiStationAPI.Models;
using AdDTO = Uranus.Service.EmployeeService.AdDTO;
using AdResponse = Uranus.Service.EmployeeService.AdResponse;

namespace Uranus.WeiStationAPI.Controllers
{
    public class ProductController : BaseController
    {
        #region 产品详情
        /// <summary>
        /// 根据编号获取产品信息
        ///   </summary>
        /// <param name="productcode">产品编号</param>
        /// <param name="type">类型</param>
        /// <returns>gid 标志 UserInfo 用户信息</returns>
        [HttpPost]
        public ResultResPonse GetProductInfoByCode()
        {
            string productCode = GetParmsKey<string>("productcode");
            string type = GetParmsKey<string>("type");
            if (!string.IsNullOrEmpty(type))
            {
                type = type.ToLower();
            }
            if (string.IsNullOrEmpty(productCode))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            LoanProductDTO loanProductDto = new LoanProductDTO();
            List<LoanProductPropertySubDTO> loanProductPropertyDtos = new List<LoanProductPropertySubDTO>();

            try
            {
                LoanProductResponse loanProductRes = Uranus.Service.Product.GetProduct().GetLoanProductByCode(new LoanProductRequest() { LoanProductDto = new LoanProductDTO() { ProductCode = productCode } });
                if (loanProductRes != null)
                {
                    loanProductDto = loanProductRes.LoanProductDto ?? new LoanProductDTO();
                }
                if (loanProductDto.ProductStatusID < 3 && type != "uranus")
                {
                    resultResPonse.code = 2;
                    return Send(resultResPonse);
                }
                if (!string.IsNullOrEmpty(loanProductDto.ProductCode))
                {
                    ControllerCommon.SyncLoanProductProgress(loanProductDto);
                    //产品属性
                    ProductPropertySubDTOResponse productPropertyRes = Uranus.Service.Product.GetProduct().GetPropertySubByProductCode(new ProductPropertySubDTORequest() { LoanProductPropertySubDto = new LoanProductPropertySubDTO() { ProductCode = loanProductDto.ProductCode } });
                    if (productPropertyRes != null)
                    {
                        loanProductPropertyDtos = productPropertyRes.List.Where(a => a.LoanProductPropertySubStatusID == 1).ToList() ?? new List<LoanProductPropertySubDTO>();
                    }
                }
                //UserDTO loanproductUserDto = new UserDTO();//借款人信息
                //List<UserPropertySubDTO> userPropertyDtos = new List<UserPropertySubDTO>();//借款人用户属性
                //List<UserPropertySubDTO> userAuthPropertyDots = new List<UserPropertySubDTO>(); //验证属性
                //List<UserPropertySubDTO> userInfoPropertyDots = new List<UserPropertySubDTO>(); //个人证属性
                //查询借款人信息
                //if (loanProductDto.UserID > 0)
                //{
                //    loanproductUserDto = Uranus.Service.User.GetUser().GetUserByUserID(loanProductDto.UserID) ?? new UserDTO();

                //    userPropertyDtos = Uranus.Service.User.GetUser().GetUserPropertySubByUserID(loanProductDto.UserID) ?? new List<UserPropertySubDTO>();
                //    userAuthPropertyDots = userPropertyDtos.Where(a => a.PropertyID == 3).ToList();//各种证明
                //    userInfoPropertyDots = userPropertyDtos.Where(a => a.PropertyID == 2).ToList();
                //}
                resultResPonse.code = 1;
                resultResPonse.data = new
                {
                    ServerTime = Uranus.Common.DateCommon.ConvertDateTimeString(DateTime.Now),
                    ProductInfo = new
                    {
                        ProductGroupID = loanProductDto.ProductGroupID,
                        ProductCode = loanProductDto.ProductCode,
                        ProductName = loanProductDto.ProductName,
                        LoanPrice = loanProductDto.LoanPrice,
                        AnnualRateOfYear = loanProductDto.AnnualRateOfYear,
                        LoanPeriod = loanProductDto.LoanPeriod,
                        LoanPeriodUnitID = loanProductDto.LoanPeriodUnitID,
                        ProductStatusID = loanProductDto.ProductStatusID,
                        RepaymentTypeID = loanProductDto.RepaymentTypeID,
                        RepaymentTypeName = loanProductDto.RepaymentTypeName,
                        CategoryID = loanProductDto.CategoryID,
                        CurrentSchedule = loanProductDto.CurrentSchedule,
                        CurrentTotalPrice = loanProductDto.CurrentLoanPrice,
                        //ProductDesc = loanProductPropertyDtos.Exists(b => b.PropertySubID == 8) ? loanProductPropertyDtos.Where(b => b.PropertySubID == 8).FirstOrDefault().InputValue : "",
                        MinBuyPrice = loanProductPropertyDtos.Exists(b => b.PropertySubID == 1) ? Convert.ToInt32(loanProductPropertyDtos.Where(b => b.PropertySubID == 1).FirstOrDefault().InputValue) : 1,
                        MaxBuyPrice = loanProductPropertyDtos.Exists(b => b.PropertySubID == 2) ? Convert.ToInt32(loanProductPropertyDtos.Where(b => b.PropertySubID == 2).FirstOrDefault().InputValue) : 0,
                        FirstTimeOnlineTime = Uranus.Common.DateCommon.ConvertDateTimeString(loanProductDto.FirstOnlineTime),
                        OrderItemCount = loanProductDto.OrderItemCount,
                        ShowAnnualRateOfYear = loanProductPropertyDtos.Exists(b => b.PropertySubID == 4) ? Convert.ToDecimal(loanProductPropertyDtos.Find(b => b.PropertySubID == 4).InputValue) : 0,//只是显示的利率
                        ProductContractUrl = loanProductPropertyDtos.Exists(a => a.PropertySubID == 23) ? loanProductPropertyDtos.Find(b => b.PropertySubID == 23).InputValue : "",
                        FullConfirmTime = Uranus.Common.DateCommon.ConvertDateTimeString(loanProductDto.FullConfirmTime),
                        CompanyID = loanProductDto.CompanyID,
                        CurrentCanBuyPrice = CommonModel.CurrentMaxHaveMoney
                        //ProductImages = loanProductPropertyDtos.Where(b => b.PropertySubID == 7).Select(c => new   //项目图片
                        //{
                        //    InputValue = c.InputValue
                        //})
                    },
                    //LoanUserInfo = new
                    //{
                    //    ID = Uranus.Common.Validates.SetHideMobile(loanproductUserDto.UserName),
                    //    Sex = loanproductUserDto.Sex,
                    //    IDCard = Uranus.Common.Validates.SetHideIDCard(loanproductUserDto.IDCard),
                    //    Age = Math.Floor((DateTime.Now - loanproductUserDto.BirthDate).TotalDays / 365),
                    //    Education = userInfoPropertyDots.Exists(a => a.PropertySubID == 10) ? userInfoPropertyDots.Where(a => a.PropertySubID == 10).FirstOrDefault().InputValue : "",
                    //    Industry = userInfoPropertyDots.Exists(a => a.PropertySubID == 17) ? userInfoPropertyDots.Where(a => a.PropertySubID == 17).FirstOrDefault().InputValue : "",
                    //    YearInCome = userInfoPropertyDots.Exists(a => a.PropertySubID == 18) ? Common.CommonModel.PriceCalc(Convert.ToInt32(userInfoPropertyDots.Where(a => a.PropertySubID == 18).FirstOrDefault().InputValue)) : "0",
                    //    City = userInfoPropertyDots.Exists(a => a.PropertySubID == 19) ? userInfoPropertyDots.Where(a => a.PropertySubID == 19).FirstOrDefault().InputValue : "",
                    //    OverDue = 0,
                    //    AuthInfo = userAuthPropertyDots.Select(a => new
                    //    {
                    //        PropertySubID = a.PropertySubID,
                    //        PropertyValue = a.PropertyValue
                    //    })
                    //}
                };
            }
            catch (Exception ex)
            {
                resultResPonse.code = 6;
                DTCash.Logger.LogHelper.WriteLogError("根据编号获取产品信息", string.Format("获取产品编号{0}异常,错误原因：{1}", productCode, ex.Message));
            }
            return Send(resultResPonse);
        }

        /// <summary>
        /// 根据产品编号获取产品描述和图片
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse ProjectDetailsByCode()
        {
            string productCode = GetParmsKey<string>("productcode");
            if (string.IsNullOrEmpty(productCode))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            //LoanProductDTO loanProductDto = new LoanProductDTO();
            List<LoanProductPropertySubDTO> loanProductPropertyDtos = new List<LoanProductPropertySubDTO>();

            ProductPropertySubDTOResponse productPropertyRes =
                Uranus.Service.Product.GetProduct()
                      .GetPropertySubByProductCode(new ProductPropertySubDTORequest()
                      {
                          LoanProductPropertySubDto = new LoanProductPropertySubDTO() { ProductCode = productCode }
                      });
            if (productPropertyRes != null)
            {
                loanProductPropertyDtos =
                    productPropertyRes.List.Where(a => a.LoanProductPropertySubStatusID == 1).ToList() ??
                    new List<LoanProductPropertySubDTO>();
                if (loanProductPropertyDtos.Count > 0)
                {
                    resultResPonse.code = 1;
                    resultResPonse.data = new
                    {
                        ServerTime = Uranus.Common.DateCommon.ConvertDateTimeString(DateTime.Now),
                        ProductInfo = new
                        {
                            ProductDesc =
                                        loanProductPropertyDtos.Exists(b => b.PropertySubID == 8)
                                            ? loanProductPropertyDtos.Where(b => b.PropertySubID == 8)
                                                                     .FirstOrDefault()
                                                                     .InputValue
                                            : "",
                            ProductImages =
                                        loanProductPropertyDtos.Where(b => b.PropertySubID == 7).Select(c => new //项目图片
                                        {
                                            InputValue = c.InputValue
                                        })
                        }
                    };
                }
                else
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "没有找到此产品！";
                }
            }
            return Send(resultResPonse);
        }
        /// <summary>
        /// 获取借款方信息
        /// </summary>
        /// <returns></returns>
        public ResultResPonse BorrowerInformationByCode()
        {
            string productCode = GetParmsKey<string>("productcode");
            if (string.IsNullOrEmpty(productCode))
            {
                resultResPonse.code = 5;
                resultResPonse.data = "产品编号不能为空！";
                return Send(resultResPonse);
            }

            LoanProductDTO dto = (Service.Product.GetProduct().GetLoanProductByCode(new LoanProductRequest()
            {
                LoanProductDto = new LoanProductDTO()
                {
                    ProductCode = productCode
                }
            }) ?? new LoanProductResponse()).LoanProductDto;

            if (dto != null && !string.IsNullOrEmpty(dto.ProductCode))
            {
                UserDTO loanproductUserDto = Service.User.GetUser().GetUserByUserID(dto.UserID);
                if (loanproductUserDto != null && loanproductUserDto.UserID > 0)
                {
                    //1借款人信息
                    UserInfoResponse userinfo = Service.ForwardProduct.GetForwardProduct().GetLoanerUserInfo(new UserInfoRequest() { Info = new UserInfoDTO() { UserID = dto.LoanerUserID > 0 ? dto.LoanerUserID : dto.UserID } }) ??
                                                            new UserInfoResponse();
                    UserStatisticsResponse userStatistics = Service.User.GetUser().GetUserStatistics(loanproductUserDto.UserID) ??
                                                            new UserStatisticsResponse();
                    decimal LoanTotalPrice = 0;
                    if (userStatistics.Code == 1 && userStatistics.UserStatisticsDto != null)
                    {
                        LoanTotalPrice = userStatistics.UserStatisticsDto.LoanTotalPrice;
                    }
                    UserInfoDTO userinfodto = new UserInfoDTO();
                    if (userinfo.Code == 1 && userinfo.Info != null)
                    {
                        userinfodto = userinfo.Info;
                    }

                    resultResPonse.code = 1;
                    resultResPonse.data = new
                    {
                        Name = Uranus.Common.Validates.SetHideFullName(loanproductUserDto.FullName),
                        Sex = loanproductUserDto.Sex == 1 ? "男" : "女",
                        Age = Math.Floor((DateTime.Now - loanproductUserDto.BirthDate).TotalDays / 365),
                        Industry = userinfodto.IndustryName,
                        YearInCome = userinfodto.AnnualIncome,
                        City = userinfodto.CompanyAddress,
                        LoanTotalPrice = LoanTotalPrice.ToString("N")
                    };
                }
                else
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "借款人信息不存在！";
                }
            }
            else
            {
                resultResPonse.code = 5;
                resultResPonse.data = "产品编号不能为空！";
            }

            return Send(resultResPonse);
        }

        /// <summary>
        /// 获取金额计算结果
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse ProductRepaymentCalcResult()
        {
            decimal money = Validates.GetDecimal(GetParmsKey<string>("money"));
            decimal annualRateOfYear = Validates.GetDecimal(GetParmsKey<string>("rate"));
            int repaymentTypeId = Validates.GetInt(GetParmsKey<string>("method"));
            int loanPeriod = Validates.GetInt(GetParmsKey<string>("loanPeriod"));
            if (money == 0 || annualRateOfYear == 0 || repaymentTypeId == 0 || loanPeriod == 0)
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            RepaymentScheduleDTO calcDto = Service.Repayment.GetRepayment().RepaymentSchedule(money, annualRateOfYear, loanPeriod, repaymentTypeId);
            resultResPonse.code = 1;
            resultResPonse.data = calcDto;
            return Send(resultResPonse);
        }
        #endregion

        /// <summary>
        /// 获取首页新手标产品编号 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetIndexNoviceProductCode()
        {
            string noviceProductCode = string.Empty;
            LoanProductResponse xinshouRes = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            {
                ProductStatusIds = new List<int>() { 3, 4 }, //募资中,已满标
                ProductGroupIds = new List<int>() { 2 }, //新手标
                PageIndex = 1,
                PageSize = 5
            }) ?? new LoanProductResponse();
            if (xinshouRes.list != null && xinshouRes.list.Count > 0)
            {
                LoanProductDTO obj = xinshouRes.list.OrderBy(a => a.ProductStatusID)
                    .FirstOrDefault(); //排序优先取募资中的
                if (obj != null && !string.IsNullOrEmpty(obj.ProductCode))
                {
                    noviceProductCode = obj.ProductCode;
                }
            }
            resultResPonse.code = 1;
            resultResPonse.data = new
            {
                noviceProductCode = noviceProductCode
            };
            return Send(resultResPonse);
        }

        [HttpPost]
        public ResultResPonse GetProductList()
        {
            List<LoanProductDTO> loanProductDtos = new List<LoanProductDTO>(); //显示到页面的list
            #region 活期

            LoanProductResponse currentProductRe = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            {
                ProductGroupIds = new List<int>() { 4 },
                ProductStatusIds = new List<int>() { 3 },
                TrusteeshipStatusIDs = new List<int>() { 2 },
                PageIndex = 1,
                PageSize = 1
            }) ?? new LoanProductResponse();
            if (currentProductRe.list != null && currentProductRe.list.Count > 0)
            {
                currentProductRe.list.ForEach(a => ControllerCommon.SyncLoanProductProgress(a));
                loanProductDtos.AddRange(currentProductRe.list.OrderBy(a => a.FirstOnlineTime));
            }
            #endregion

            #region 定期

            LoanProductResponse loanProductResponse = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            {
                ProductGroupIds = new List<int>() { 1 },
                ProductStatusIds = new List<int>() { 3 },
                TrusteeshipStatusIDs = new List<int>() { 2 },
                PageIndex = 1,
                PageSize = 5
            }) ?? new LoanProductResponse();
            if (loanProductResponse.list != null && loanProductResponse.list.Count > 0)
            {
                loanProductResponse.list.ForEach(a => ControllerCommon.SyncLoanProductProgress(a));
                //if (loanProductResponse.list.Exists(a => a.ProductStatusID == 3))
                //{
                loanProductDtos.AddRange(loanProductResponse.list.OrderBy(a => a.FirstOnlineTime));
                //}
            }
            #endregion


            #region 新手标

            //bool isNoviceUser = UserInfo == null || UserInfo.UserID == 0 || UserInfo.InvestCount == 0;
            //LoanProductResponse xinshouRes = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            //{
            //    ProductStatusIds = new List<int>() { 3 },
            //    ProductGroupIds = new List<int>() { 2 },
            //    PageIndex = 1,
            //    PageSize = 1
            //}) ?? new LoanProductResponse();
            //if (xinshouRes.list != null && xinshouRes.list.Count > 0)
            //{
            //    xinshouRes.list.ForEach(a => ControllerCommon.SyncLoanProductProgress(a));
            //    if (xinshouRes.list.Exists(a => a.ProductStatusID == 3))
            //    {
            //        if (isNoviceUser)
            //        {
            //            loanProductDtos.Insert(0, xinshouRes.list.OrderBy(a => a.FirstOnlineTime).FirstOrDefault(a => a.ProductStatusID == 3));
            //        }
            //        else
            //        {
            //            loanProductDtos.Add(xinshouRes.list.OrderBy(a => a.FirstOnlineTime).FirstOrDefault(a => a.ProductStatusID == 3));
            //        }
            //    }
            //}

            #endregion

            //查询5个已经满标的产品,与分组无关
            //LoanProductResponse manloanProductResponse = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            //{
            //    ProductStatusIds = new List<int>() { 4, 5, 6, 7 },
            //    TrusteeshipStatusIDs = new List<int>() { 2, 3 },
            //    PageIndex = 1,
            //    PageSize = 5
            //}) ?? new LoanProductResponse();
            //if (manloanProductResponse.list != null && manloanProductResponse.list.Count > 0)
            //{
            //    manloanProductResponse.list.ForEach(a => ControllerCommon.SyncLoanProductProgress(a));
            //    loanProductDtos.AddRange(manloanProductResponse.list);
            //}
            List<LoanProductAndPropertySub> loanProductAndPropertySubs = new List<LoanProductAndPropertySub>();
            //填充数据 准备验证取属性
            loanProductDtos.ForEach(a => loanProductAndPropertySubs.Add(new LoanProductAndPropertySub()
            {
                LoanProductDto = a
            }));
            loanProductAndPropertySubs.ForEach(a =>
                {
                    a.PropertyList =
                        Service.Product.GetProduct().GetPropertySubByProductCode(new ProductPropertySubDTORequest()
                        {
                            LoanProductPropertySubDto = new LoanProductPropertySubDTO()
                            {
                                ProductCode = a.LoanProductDto.ProductCode
                            }
                        }).List ?? new List<LoanProductPropertySubDTO>();
                });
            resultResPonse.code = 1;
            resultResPonse.data = loanProductAndPropertySubs.Where(b => b.LoanProductDto.ProductStatusID == 3).Select(
                a => new
                {
                    ProductName = a.LoanProductDto.ProductName,
                    ProductStatusID = a.LoanProductDto.ProductStatusID,
                    ProductCode = a.LoanProductDto.ProductCode,
                    CurrentLoanPrice = a.LoanProductDto.CurrentLoanPrice,
                    LoanPrice = a.LoanProductDto.LoanPrice,
                    LoanPeriod = a.LoanProductDto.LoanPeriod,
                    LoanPeriodUnitID = a.LoanProductDto.LoanPeriodUnitID,
                    ProductGroupID = a.LoanProductDto.ProductGroupID,
                    ProductGroupName = a.LoanProductDto.ProductGroupName,
                    RepaymentTypeName = a.LoanProductDto.RepaymentTypeName,
                    RepaymentTypeID = a.LoanProductDto.RepaymentTypeID,
                    AnnualRateOfYear = a.LoanProductDto.AnnualRateOfYear,
                    FirstOnlineTime = DateCommon.ConvertDateTimeString(a.LoanProductDto.FirstOnlineTime),
                    BidExpireTime = DateCommon.ConvertDateTimeString(a.LoanProductDto.BidExpireTime),
                    CurrentSchedule = Math.Floor(a.LoanProductDto.CurrentSchedule * 100),
                    ShowAnnualRateOfYear =
                    a.PropertyList.Exists(b => b.PropertySubID == 4)
                        ? Convert.ToDecimal(a.PropertyList.Find(b => b.PropertySubID == 4).InputValue)
                        : 0, //只是显示的利率
                    IsActive = a.PropertyList.Exists(b => b.PropertySubID == 6),
                    IsReturnCash = a.PropertyList.Exists(b => b.PropertySubID == 39),
                    OrderItemCount = a.LoanProductDto.OrderItemCount
                    //IsTiyan = a.PropertyList.Exists(b => b.PropertySubID == 21),//体验产品 2017年9月28日15:29:04  产品组里没有体验产品了
                }).OrderBy(c => c.LoanPeriod).ToList().OrderByDescending(c => c.ProductGroupID).ToList();
            return Send(resultResPonse);

        }

        #region 购买流程
        /// <summary>
        /// 购买定期产品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UserState(VisitUserStateEnum = VisitUserStateEnum.MustLogin, EnAuthHuifu = true)]
        public ResultResPonse SetOrderConfirmPayment()
        {
            decimal buyprice = GetParmsKey<decimal>("buyprice");
            string productcode = GetParmsKey<string>("productcode");
            string type = GetParmsKey<string>("type");
            if (buyprice == 0 || string.IsNullOrEmpty(productcode))
            {
                resultResPonse.code = 3;//参数非法
                return Send(resultResPonse);
            }
            if (string.IsNullOrEmpty(UserInfo.HuiFuCode))
            {
                resultResPonse.code = 5;//参数非法
                resultResPonse.data = "未开通汇付";
                return Send(resultResPonse);

            }
            //获取产品信息 
            LoanProductResponse loanProductRes = Uranus.Service.Product.GetProduct().GetLoanProductByCode(new LoanProductRequest() { LoanProductDto = new LoanProductDTO() { ProductCode = productcode } });
            if (loanProductRes != null && loanProductRes.Code == 1)
            {
                DateTime now = DateTime.Now;
                LoanProductDTO loanProductDto = loanProductRes.LoanProductDto;
                if (loanProductDto.FirstOnlineTime > now)
                {
                    //产品从上线开始显示的倒计时
                    resultResPonse.code = 5;
                    if (now.Day == loanProductDto.FirstOnlineTime.Day)
                    {
                        resultResPonse.data = loanProductDto.FirstOnlineTime.ToString("HH:mm") + "开售";
                    }
                    else
                    {
                        resultResPonse.data = loanProductDto.FirstOnlineTime.ToString("yyyy-MM-dd HH:mm") + "开售";
                    }
                    return Send(resultResPonse);
                }
                if (loanProductDto.ProductStatusID < 3)
                {
                    if (!(loanProductDto.ProductStatusID == 1 && type.ToLower() == "uranus"))
                    {
                        resultResPonse.code = 2;
                        return Send(resultResPonse);
                    }
                }
                decimal minbuyprice = 1,
                        //最小购买金额
                        maxbuyprice = 0,
                        //最大购买金额
                        activerateofyear = 0;//活动显示年化收益

                #region 新手标判断
                if (loanProductRes.LoanProductDto.ProductGroupID == 2)
                {
                    /*读取配置中心，若取值和当前用户ID一致,则拥有 开通永久存入权限*/
                    object noviceWhiteUser = ConfigCenterWork.GetConfigValueByOperationType(15);//新手标白名单用户
                    if (noviceWhiteUser != null)
                    {
                        string[] supportarray = noviceWhiteUser.ToString().Split(',');
                        if (!supportarray.Contains(UserInfo.UserID.ToString()))
                        {
                            if (UserInfo.InvestCount > 0)
                            {
                                resultResPonse.code = 5;
                                resultResPonse.data = "仅限新手用户购买";
                                return Send(resultResPonse);
                            }
                        }
                    }
                    else
                    {
                        if (UserInfo.HuiFuCreateTime.Date.AddDays(5) < DateTime.Now || UserInfo.InvestCount > 0)
                        {
                            resultResPonse.code = 5;
                            resultResPonse.data = "仅限新手用户购买";
                            return Send(resultResPonse);
                        }
                    }
                }
                #endregion

                #region 获取产品属性
                ProductPropertySubDTOResponse productPropertyDtosRes = Uranus.Service.Product.GetProduct().GetPropertySubByProductCode(new ProductPropertySubDTORequest() { LoanProductPropertySubDto = new LoanProductPropertySubDTO() { ProductCode = productcode } });
                List<LoanProductPropertySubDTO> propertyList = new List<LoanProductPropertySubDTO>();
                if (productPropertyDtosRes != null)
                {
                    propertyList = productPropertyDtosRes.List.Where(a => a.LoanProductPropertySubStatusID == 1).ToList() ?? new List<LoanProductPropertySubDTO>();
                }
                if (propertyList.Exists(a => a.PropertySubID == 1))//最小购买金额
                {
                    minbuyprice = Convert.ToInt32(propertyList.Where(a => a.PropertySubID == 1).FirstOrDefault().InputValue);
                }
                if (propertyList.Exists(a => a.PropertySubID == 2))//最大购买金额
                {
                    maxbuyprice = Convert.ToInt32(propertyList.Where(a => a.PropertySubID == 2).FirstOrDefault().InputValue);
                }
                if (propertyList.Exists(a => a.PropertySubID == 4))//活动显示年化收益
                {
                    activerateofyear = Convert.ToDecimal(propertyList.Where(a => a.PropertySubID == 4).FirstOrDefault().InputValue);
                }
                #endregion

                if (minbuyprice < 1) minbuyprice = 1;
                if (!string.IsNullOrEmpty(loanProductDto.ProductCode))
                {
                    ControllerCommon.SyncLoanProductProgress(loanProductDto);
                }
                if (maxbuyprice < 1) maxbuyprice = loanProductDto.LoanPrice - loanProductDto.CurrentLoanPrice;
                //, isNoviceUser = true;
                if (buyprice < minbuyprice)
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "该产品购买金额最少为" + minbuyprice + "元"; ;
                    return Send(resultResPonse);
                }
                if (buyprice % minbuyprice != 0)
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "请输入" + minbuyprice + "的倍数"; ;
                    return Send(resultResPonse);
                }
                if (maxbuyprice > 0 && buyprice > maxbuyprice)
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "单笔最多可购买" + maxbuyprice + "元"; ;
                    return Send(resultResPonse);
                }
                UserDTO user = Uranus.Service.User.GetUser().GetUserByUserID(loanProductDto.UserID);
                if (user == null || user.UserID <= 0)
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "借款人信息获取失败，请稍后再试"; ;
                    return Send(resultResPonse);
                }
                if (user.UserID == UserInfo.UserID)
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "不能投资自己的产品"; ;
                    return Send(resultResPonse);
                }
                if (string.IsNullOrEmpty(user.HuiFuCode))
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "借款人未开通汇付天下，无法投资"; ;
                    return Send(resultResPonse);
                }
                InspectionProductResponse inspectionProductRes = Uranus.Service.Product.GetProduct().InspectionProduct(new InspectionProductRequest() { ProductCode = productcode, IsNotCheckUsablePrice = true, InvestmentPrice = buyprice, UserID = UserInfo.UserID });
                if (inspectionProductRes != null)
                {
                    if (inspectionProductRes.Code == 1 || type == "uranus")//加上预览功能
                    {
                        //创建订单
                        decimal predictEarning = 0;
                        //计算收益
                        RepaymentScheduleDTO repaymentScheduleDto = Uranus.Service.Repayment.GetRepayment().RepaymentSchedule(buyprice, loanProductDto.AnnualRateOfYear, loanProductDto.LoanPeriod, loanProductDto.RepaymentTypeID);
                        if (repaymentScheduleDto != null)
                        {
                            predictEarning = repaymentScheduleDto.InvestInterest;//投资利息
                            //InvestPrice 投资金额  InvestPrincipal本息
                        }
                        string gid = Guid.NewGuid().ToString("N");
                        UserShopInfo userShop = new UserShopInfo();
                        userShop.ProductCode = productcode;
                        userShop.LoanPrice = loanProductDto.LoanPrice;
                        userShop.LoanPeriodUnitID = loanProductDto.LoanPeriodUnitID;
                        userShop.ProductGroupID = loanProductDto.ProductGroupID;
                        userShop.ProductName = loanProductDto.ProductName;
                        userShop.RepaymentTypeID = loanProductDto.RepaymentTypeID;
                        userShop.RepaymentTypeName = loanProductDto.RepaymentTypeName;
                        userShop.UserID = UserInfo.UserID;
                        userShop.AnnualRateOfYear = loanProductDto.AnnualRateOfYear;
                        userShop.BuyPrice = buyprice;
                        userShop.LoanPeriod = loanProductDto.LoanPeriod;
                        userShop.CategoryID = loanProductDto.CategoryID;
                        userShop.InterestAmt = predictEarning;
                        userShop.ActiveRateOfYear = activerateofyear;
                        userShop.ProId = loanProductDto.ProID;
                        userShop.LHuifuCode = user.HuiFuCode;
                        userShop.IsCurrent = loanProductDto.ProductGroupID == 4;
                        CacheKey cacheKey = CacheItem.InitByIdentity(gid, "Confirmation").Other.other;

                        CacheRedis.AddCache(userShop, cacheKey);
                        resultResPonse.code = 1;
                        resultResPonse.data = gid;
                    }
                    else if (inspectionProductRes.Code == 3)
                    {
                        resultResPonse.code = 5;
                        resultResPonse.data = inspectionProductRes.ResposeData;
                    }
                    else
                    {
                        LogHelper.WriteLogError("用户" + UserInfo.UserID + "购买定期产品" + productcode + "失败", "失败原因:" + inspectionProductRes.ResposeData);
                        resultResPonse.code = 5;
                        resultResPonse.data = "购买失败，请稍后再试"; ;
                        return Send(resultResPonse);
                    }
                }
                else
                {
                    resultResPonse.code = 5;
                    resultResPonse.data = "购买失败，请稍后再试"; ;
                    return Send(resultResPonse);
                }
            }
            else
            {
                resultResPonse.code = 5;
                resultResPonse.data = "购买失败，请稍后再试"; ;
                return Send(resultResPonse);
            }
            return Send(resultResPonse);
        }

        /// <summary>
        /// 获取订单确认详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UserState(VisitUserStateEnum = VisitUserStateEnum.ObtainUserInfo)]
        public ResultResPonse GetOrderConfirmPayment()
        {
            string id = GetParmsKey<string>("id");
            if (string.IsNullOrEmpty(id))
            {
                resultResPonse.code = 3;//订单记录不存在
                return Send(resultResPonse);
            }
            CacheKey cacheKey = CacheItem.InitByIdentity(id, "Confirmation").Other.other;
            if (!CacheRedis.ExistsRedis(cacheKey))
            {
                resultResPonse.code = 110;//订单记录不存在
                return Send(resultResPonse);
            }
            UserShopInfo userShopInfo = CacheRedis.GetCache(cacheKey) as UserShopInfo;
            if (userShopInfo == null || userShopInfo.UserID != UserInfo.UserID)
            {
                resultResPonse.code = 110;//订单记录不存在
                return Send(resultResPonse);
            }

            GiftCardResponse giftCardResponse = Uranus.Service.User.GetUser().GetGiftCardDTOList(
                                                    new Service.UserService.GiftCardRequest()
                                                    {
                                                        PageIndex = 1,
                                                        PageSize = 100,
                                                        UserID = UserInfo.UserID,
                                                        GiftCardTypeIDs = new List<int> { 2 },
                                                        GiftCardStatusIDs = new List<int> { 1 },
                                                    }) ?? new GiftCardResponse() { GiftCardDtos = new List<GiftCardDTO>() };


            bool isUseRateCard = false, isUseCashCard = false;
            ProductPropertySubDTOResponse productPropertyRes = Uranus.Service.Product.GetProduct()
                .GetPropertySubByProductCode(new ProductPropertySubDTORequest()
                {
                    LoanProductPropertySubDto = new LoanProductPropertySubDTO() { ProductCode = userShopInfo.ProductCode }
                });
            if (productPropertyRes != null)
            {
                List<int> useCards = productPropertyRes.List.Where(p => p.PropertySubID == 38)
                    .Select(p => Validates.GetInt(p.InputValue)).ToList();
                isUseRateCard = useCards.Contains(2);
                isUseCashCard = useCards.Contains(5);
            }

            decimal activationCash = Service.Product.GetProduct()
                .GetActivationRedPacketValue(userShopInfo.ProductCode, userShopInfo.BuyPrice, UserInfo.UserID);

            resultResPonse.code = 1;
            resultResPonse.data = new
            {
                AnnualRateOfYear = userShopInfo.AnnualRateOfYear,
                BuyPrice = userShopInfo.BuyPrice,
                CategoryID = userShopInfo.CategoryID,
                LoanPeriod = userShopInfo.LoanPeriod,
                LoanPeriodUnitID = userShopInfo.LoanPeriodUnitID,
                LoanPrice = userShopInfo.LoanPrice,
                ProductCode = userShopInfo.ProductCode,
                ProductGroupID = userShopInfo.ProductGroupID,
                ProductName = userShopInfo.ProductName,
                RepaymentTypeID = userShopInfo.RepaymentTypeID,
                RepaymentTypeName = userShopInfo.RepaymentTypeName,
                UsablePrice = UserInfo.UsablePrice,
                PredictEarning = userShopInfo.InterestAmt, //预期收益
                ActiveRateOfYear = userShopInfo.ActiveRateOfYear,
                HaveGiftCard = giftCardResponse.GiftCardDtos.Exists(p => p.ExpiredTime > DateTime.Now),
                IsUseRateCard = isUseRateCard,
                IsUseCashCard = isUseCashCard,
                ActivationCash = activationCash,
                IsCurrent = userShopInfo.IsCurrent
            };
            return Send(resultResPonse);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UserState(VisitUserStateEnum = VisitUserStateEnum.ObtainUserInfo)]
        public ResultResPonse ConfirmGiftCard()
        {
            string id = GetParmsKey<string>("id");
            string type = GetParmsKey<string>("type");
            string giftCardId = GetParmsKey<string>("gcid");
            if (string.IsNullOrEmpty(id))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            if (type != "clear" && string.IsNullOrEmpty(giftCardId))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            CacheKey cacheKey = CacheItem.InitByIdentity(id, "Confirmation").Other.other;
            if (!CacheRedis.ExistsRedis(cacheKey))
            {
                resultResPonse.code = 110;//订单记录不存在
                return Send(resultResPonse);
            }
            UserShopInfo userShopInfo = CacheRedis.GetCache(cacheKey) as UserShopInfo;
            if (userShopInfo == null || userShopInfo.UserID != UserInfo.UserID)
            {
                resultResPonse.code = 110;//订单记录不存在
                return Send(resultResPonse);
            }

            resultResPonse.code = 1;
            if (type == "clear")
            {
                userShopInfo.GiftCardID = 0;
            }
            else
            {
                GiftCardResponse giftCardResponse = Service.User.GetUser().GetGiftCardDTOList(new GiftCardRequest()
                {
                    GiftCardStatusIDs = new List<int>() { 1 },
                    GiftCardTypeIDs = new List<int>() { 2 },
                    GiftCardID = Validates.GetInt(giftCardId),
                    UserID = UserInfo.UserID,
                    PageIndex = 1,
                    PageSize = 1
                });
                if (giftCardResponse.Code != 1)
                {
                    resultResPonse.code = 7;
                    return Send(resultResPonse);
                }
                if (!giftCardResponse.GiftCardDtos.Exists(p => p.ExpiredTime > DateTime.Now))
                {
                    resultResPonse.code = 10;
                    resultResPonse.data = "该礼品卡不可用";
                    return Send(resultResPonse);
                }
                userShopInfo.GiftCardID = giftCardResponse.GiftCardDtos[0].GiftCardID;
                RepaymentScheduleDTO repaymentScheduleDto = Service.Repayment.GetRepayment().RepaymentSchedule(userShopInfo.BuyPrice,
                    giftCardResponse.GiftCardDtos[0].GiftCardValue, userShopInfo.LoanPeriod,
                    userShopInfo.RepaymentTypeID);
                resultResPonse.data = repaymentScheduleDto.InvestInterest.ToString("f2");
            }

            CacheRedis.AddCache(userShopInfo, cacheKey);
            return Send(resultResPonse);
        }

        #endregion

        /// <summary>
        /// 获取广告列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse AdList()
        {
            int num = GetParmsKey<int>("num");
            int type = GetParmsKey<int>("typeid");
            num = num < 1 ? 5 : num;
            type = type < 1 ? 1 : type;
            List<AdDTO> adDtos = new List<AdDTO>();

            try
            {
                AdResponse adRes = Employee.GetEmployee().GetAdDTOList(new Service.EmployeeService.AdRequest() { AdDto = new AdDTO() { AdTypeID = type }, AdTypeId = type, PageIndex = 1, PageSize = num });
                if (adRes != null && adRes.AdDtos != null)
                {
                    adDtos = adRes.AdDtos ?? new List<AdDTO>();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogError("获取广告异常", "type:" + type, ex);
            }
            resultResPonse.code = 1;
            resultResPonse.data = adDtos.Where(b => b.StartTime <= DateTime.Now && b.EndTime >= DateTime.Now).Select(a => new
            {
                AdImage = a.AdImage,
                AdUrl = a.AdUrl
            });
            return Send(resultResPonse);
        }

        [UserState]
        [HttpPost]
        public ResultResPonse GetHeTongByProductCode()
        {
            string productcode = GetParmsKey<string>("productcode");
            if (string.IsNullOrEmpty(productcode))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            ProductPropertySubDTOResponse propertySubDTOResponse = Uranus.Service.Product.GetProduct().GetPropertySubByProductCode(new ProductPropertySubDTORequest()
            {
                LoanProductPropertySubDto = new LoanProductPropertySubDTO()
                {
                    ProductCode = productcode
                }
            });
            if (propertySubDTOResponse == null)
            {
                resultResPonse.code = 6;
                return Send(resultResPonse);
            }
            resultResPonse.code = 1;
            resultResPonse.data =
                propertySubDTOResponse.List.Where(a => a.PropertySubID == 22).Select(a => new
                {
                    InputValue = a.InputValue
                });
            return Send(resultResPonse);
        }

        /// <summary>
        /// 根据产品编号查询子订单信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetOrderItemByProductCode()
        {
            string productcode = GetParmsKey<string>("productcode");
            string start = GetParmsKey<string>("start");
            string end = GetParmsKey<string>("end");
            if (string.IsNullOrEmpty(productcode) || string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            int pagestart, pageend;
            if (!int.TryParse(start, out pagestart) || !int.TryParse(end, out pageend))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            OrderItemRequest request = new OrderItemRequest();
            request.OrderItemDto = new OrderItemDTO();
            request.OrderItemDto.ProductCode = productcode;
            request.PageStart = pagestart;
            request.PageEnd = pageend;

            OrderItemResponse orderItemRes = Service.Order.GetOrder().GetOrderItemsPage(request);
            if (orderItemRes != null && orderItemRes.OrderItemDtos != null)
            {
                resultResPonse.code = 1;

                resultResPonse.data = new
                {
                    total = orderItemRes.Total,
                    list = orderItemRes.OrderItemDtos.OrderByDescending(a => a.PaymentTime).Select(a => new
                    {
                        username = Uranus.Common.Validates.SetHideMobile(a.Mobile),
                        price = a.OrderItemPrice,
                        createtime = Uranus.Common.DateCommon.ConvertDateTimeString(a.PaymentTime),
                    })
                };

                return Send(resultResPonse);
            }
            else
            {
                resultResPonse.code = 6;
                return Send(resultResPonse);
            }
        }

        /// <summary>
        /// 获取用户订单信息
        /// Date:2017-10-23 00:00:00
        /// Author:Linsan
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UserState(VisitUserStateEnum = VisitUserStateEnum.MustLogin)]
        public ResultResPonse GetOrderItemByID()
        {
            if (UserInfo == null || UserInfo.UserID == 0)
            {
                resultResPonse.code = 8;
                return Send(resultResPonse);
            }
            string id = GetParmsKey<string>("id");
            int oid;
            if (string.IsNullOrEmpty(id) || !int.TryParse(id, out oid))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            Uranus.Service.OrderService.OrderItemDTO orderItem = Uranus.Service.Order.GetOrder().GetOrderItemById(oid);
            if (orderItem != null)
            {
                List<UserGiftCardDTO> userGiftCardDtos = new List<UserGiftCardDTO>();
                UserGiftCardResponse userGiftCardResponse = Service.User.GetUser().GetUserGiftCardDTOList(
                    new UserGiftCardRequest()
                    {
                        UserID = UserInfo.UserID,
                        OrderItemID = oid,
                        GiftCardTypeIDs = new List<int>() { 2 }
                    });
                if (userGiftCardResponse.Code == 1)
                {
                    userGiftCardDtos = userGiftCardResponse.UserGiftCardDtos;
                }
                decimal allGiftCardValue = userGiftCardDtos.Sum(p => p.GiftCardValue);
                decimal allPrice = userGiftCardDtos.Sum(p => p.Price);
                resultResPonse.code = 1;
                resultResPonse.data = new
                {
                    orderItem,
                    cards = userGiftCardDtos.Select(p => new
                    {
                        cardId = p.GiftCardID,
                        cardRate = p.GiftCardValue,
                    }),
                    allCardRate = allGiftCardValue,
                    allCardPrice = allPrice
                };
                return Send(resultResPonse);
            }
            resultResPonse.code = 2;
            return Send(resultResPonse);
        }

        /// <summary>
        /// 获取用户还款单信息
        /// Date:2017-10-23 00:00:00
        /// Author:Linsan
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UserState(VisitUserStateEnum = VisitUserStateEnum.MustLogin)]
        public ResultResPonse GetrepaymentListByID()
        {
            string id = GetParmsKey<string>("id");
            int oid;
            if (string.IsNullOrEmpty(id) || !int.TryParse(id, out oid))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            RepaymentItemFormResponse response = Uranus.Service.Repayment.GetRepayment().GetRepaymentItemFormDTOList(new RepaymentItemFormRequest()
            {
                OrderItemID = oid
            });
            if (response != null && response.Code == 1)
            {
                resultResPonse.code = 1;
                resultResPonse.data = new
                {
                    totalInterest = response.RepaymentItemFormDtos.Sum(a => a.RepayInterest + a.ExtraIncome),
                    list = response.RepaymentItemFormDtos.Select(a => new
                    {
                        RepaymentItemFormID = a.RepaymentItemFormID,
                        RepayPrincipal = a.RepayPrincipal,
                        RepayInterest = a.RepayInterest + a.ExtraIncome,
                        RepayTime = Uranus.Common.DateCommon.ConvertDateTimeString(a.RepayTime),
                        RepaymentItemFormStatusID = a.RepaymentItemFormStatusID
                    })
                };
                return Send(resultResPonse);
            }
            resultResPonse.code = 2;
            return Send(resultResPonse);
        }

        /// <summary>
        /// 计算产品收益
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetProductRevenue()
        {
            decimal buyprice = GetParmsKey<decimal>("buyprice");
            string productcode = GetParmsKey<string>("productcode");
            if (string.IsNullOrEmpty(productcode) || buyprice == 0)
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            LoanProductResponse loanProductRes = Uranus.Service.Product.GetProduct().GetLoanProductByCode(new LoanProductRequest() { LoanProductDto = new LoanProductDTO() { ProductCode = productcode } });
            if (loanProductRes != null && loanProductRes.Code == 1)
            {
                LoanProductDTO loanProductDto = loanProductRes.LoanProductDto;
                RepaymentScheduleDTO repaymentScheduleDto =
                    Uranus.Service.Repayment.GetRepayment()
                        .RepaymentSchedule(buyprice, loanProductDto.AnnualRateOfYear, loanProductDto.ProductGroupID == 4 ? 1 : loanProductDto.LoanPeriod,
                            loanProductDto.RepaymentTypeID);
                if (repaymentScheduleDto != null)
                {
                    //predictEarning = repaymentScheduleDto.InvestInterest;//投资利息
                    //InvestPrice 投资金额  InvestPrincipal本息
                    resultResPonse.code = 1;
                    resultResPonse.data = repaymentScheduleDto.InvestInterest; //投资利息
                    return Send(resultResPonse);
                }
            }
            resultResPonse.code = 2;
            return Send(resultResPonse);
        }

        /// <summary>
        /// 获取担保机构
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetCompany()
        {
            string cid = GetParmsKey<string>("id");
            int companyId;
            if (string.IsNullOrEmpty(cid) || !int.TryParse(cid, out companyId))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            CompanyResponse response = Uranus.Service.Company.GetCompany().GetCompany(companyId);
            if (response != null && response.Code == 1)
            {
                CompanyDTO dompanyDto = response.CompanyDto;
                if (dompanyDto != null)
                {
                    resultResPonse.code = 1;
                    resultResPonse.data = dompanyDto;
                    return Send(resultResPonse);
                }
            }
            resultResPonse.code = 2;
            return Send(resultResPonse);
        }

        /// <summary>
        /// 查询产品担保机构统计信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetCompanyStatistics()
        {
            string cid = GetParmsKey<string>("id");
            int companyId;
            if (string.IsNullOrEmpty(cid) || !int.TryParse(cid, out companyId))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }
            CompanyStatisticsBaseResponse response = Uranus.Service.Company.GetCompany().CompanyStatistics(new CompanyStatisticsBaseRequest { CompanyId = companyId });
            if (response != null && response.Code == 1)
            {
                CompanyStatisticsDTO companyStatisticsDto = response.CompanyStatisticsDto;
                if (companyStatisticsDto != null)
                {
                    resultResPonse.code = 1;
                    resultResPonse.data = companyStatisticsDto;
                    return Send(resultResPonse);
                }
            }
            resultResPonse.code = 2;
            return Send(resultResPonse);
        }

        /// <summary>
        /// 获取数据纰漏信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetDisclosureData()
        {
            DisclosureDTO disclosureDto = Service.Product.GetProduct().GetDisclosureDto();
            if (disclosureDto == null)
            {
                resultResPonse.code = 6;
            }
            else
            {
                int configRegisterCount = Validates.GetInt(ConfigCenterWork.GetConfigValueByOperationType(17));
                resultResPonse.code = 1;
                resultResPonse.data = new
                {
                    registCount = (configRegisterCount + disclosureDto.RegisterUserCount).ToString("N0")
                };
            }

            return Send(resultResPonse);
        }

        /// <summary>
        /// 根据条件查询产品编号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultResPonse GetProductCodeByParams()
        {
            resultResPonse.code = 0;
            string groupid = GetParmsKey<string>("groupid");
            string peroidid = GetParmsKey<string>("peroidid");

            int gid = 0;
            int pid = 0;
            if (!int.TryParse(groupid, out gid) || !int.TryParse(peroidid, out pid))
            {
                resultResPonse.code = 3;
                return Send(resultResPonse);
            }

            LoanProductDTO loanProductDto = new LoanProductDTO();
            LoanProductResponse productRes = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
            {
                ProductGroupIds = new List<int>() { gid },
                ProductStatusIds = new List<int>() { 3 },
                TrusteeshipStatusIDs = new List<int>() { 2 },
                LoanPeroidIds = gid != 4 ? new List<int> { pid } : new List<int> { },
                PageIndex = 1,
                PageSize = 1
            }) ?? new LoanProductResponse();
            if (productRes.list != null && productRes.list.Count > 0)
            {
                loanProductDto = productRes.list[0];
                resultResPonse.code = 1;
            }
            else
            {
                LoanProductResponse productRess = Service.Product.GetProduct().GetLoanProductDTOList(new LoanProductRequest()
                {
                    ProductGroupIds = new List<int>() { gid },
                    ProductStatusIds = new List<int>() { 5 },
                    TrusteeshipStatusIDs = new List<int>() { 2 },
                    LoanPeroidIds = gid != 4 ? new List<int> { pid } : new List<int> { },
                    PageIndex = 1,
                    PageSize = 1
                }) ?? new LoanProductResponse();
                if (productRess.list != null && productRess.list.Count > 0)
                {
                    loanProductDto = productRess.list[0];
                    resultResPonse.code = 1;
                }
            }
            resultResPonse.data = loanProductDto != null && !string.IsNullOrEmpty(loanProductDto.ProductCode)
                ? loanProductDto.ProductCode
                : "";
            return Send(resultResPonse);

        }
    }
}
